package com.supermap.shiro.auth.entity;

import com.supermap.dubbo.api.user.entity.BindUser;
import com.supermap.dubbo.api.user.entity.User;

import java.io.Serializable;
import java.util.Objects;

/**
 * @author xiaolu
 * @date 2018/7/4 上午10:52
 */
public class AppUser implements Serializable {
    private String loginName;
    private String password;
    private String realPassword;
    private String roleCode;
    private String createTime;
    private String showName;
    private String headImage;
    private String mobile;
    private String email;
    private String areaCode;
    private String address;
    private String introduction;
    private String id;
    private String state;
    private String username;
    private String realName;
    private double latitude;
    private double longitude;
    private String bindName;
    private String bindPwd;
    //物联网
    private String loginIotName;
    private String loginIotPassword;

    public void setLoginIotName(String loginIotName) {
        this.loginIotName = loginIotName;
    }

    public void setLoginIotPassword(String loginIotPassword) {
        this.loginIotPassword = loginIotPassword;
    }

    public String getLoginIotName() {
        return loginIotName;
    }

    public String getLoginIotPassword() {
        return loginIotPassword;
    }

    public AppUser() {
    }

    public AppUser(AppUser appUser) {
        this.loginName = appUser.getLoginName();
        this.password = appUser.getPassword();
        this.realPassword = appUser.getRealPassword();
        this.roleCode = appUser.getRoleCode();
        this.createTime = appUser.getCreateTime();
        this.showName = appUser.getShowName();
        this.headImage = appUser.getHeadImage();
        this.mobile = appUser.getMobile();
        this.email = appUser.getEmail();
        this.areaCode = appUser.getAreaCode();
        this.address = appUser.getAddress();
        this.introduction = appUser.getIntroduction();
        this.id = appUser.getId();
        this.state = appUser.getState();
        this.username = appUser.getUsername();
        this.realName = appUser.getRealName();
        this.latitude = appUser.getLatitude();
        this.longitude = appUser.getLongitude();
        this.bindName = appUser.getBindName();
        this.bindPwd = appUser.getBindPwd();
    }

    public AppUser(String loginName, String realPassword) {
        this.loginName = loginName;
        this.realPassword = realPassword;
    }

    public AppUser(User appUser) {
        this.showName = appUser.getShowName();
        this.loginName = appUser.getLoginName();
        this.mobile = appUser.getMobile();
        this.address = appUser.getAddress();
        this.areaCode = appUser.getAreaCode();
        this.introduction = appUser.getIntroduction();
        this.headImage = appUser.getHeadImage();
        this.email = appUser.getEmail();
        this.latitude = getNumber(appUser.getLatitude());
        this.longitude = getNumber(appUser.getLongitude());
        this.id = String.valueOf(appUser.getId());
        this.password = appUser.getPassword();
        this.roleCode = appUser.getRolecode();
        this.state = appUser.getState();
        this.username = appUser.getUsername();
    }

    private double getNumber(String number) {
        if(Objects.isNull(number)){
            return 0;
        }
        double num = 0;
        try {
            num = Double.parseDouble(number);
        }catch (Exception e){

        }
        return num;
    }

    public User assistToUser() {
        User user = new User();

        user.setShowName(this.showName);
        user.setLoginName(this.loginName);
        user.setMobile(this.mobile);
        user.setAddress(this.address);
        user.setAreaCode(this.areaCode);
        user.setIntroduction(this.introduction);
        user.setHeadImage(this.headImage);
        user.setEmail(this.email);
        user.setLatitude(String.valueOf(this.latitude));
        user.setLongitude(String.valueOf(this.longitude));

        user.setPassword(this.password);
        user.setRolecode(this.roleCode);
        user.setId(Integer.parseInt(this.id));
        user.setState(this.state);
        user.setUsername(this.username);
        return user;
    }

    public String getLoginName() {
        return loginName;
    }

    public void setLoginName(String loginName) {
        this.loginName = loginName;
    }

    public String getBindName() {
        return bindName;
    }

    public void setBindName(String bindName) {
        this.bindName = bindName;
    }

    public String getBindPwd() {
        return bindPwd;
    }

    public void setBindPwd(String bindPwd) {
        this.bindPwd = bindPwd;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getRealPassword() {
        return realPassword;
    }

    public void setRealPassword(String realPassword) {
        this.realPassword = realPassword;
    }

    public String getRoleCode() {
        return roleCode;
    }

    public void setRoleCode(String roleCode) {
        this.roleCode = roleCode;
    }

    public String getCreateTime() {
        return createTime;
    }

    public void setCreateTime(String createTime) {
        this.createTime = createTime;
    }

    public String getShowName() {
        return showName;
    }

    public void setShowName(String showName) {
        this.showName = showName;
    }

    public String getHeadImage() {
        return headImage;
    }

    public void setHeadImage(String headImage) {
        this.headImage = headImage;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getAreaCode() {
        return areaCode;
    }

    public void setAreaCode(String areaCode) {
        this.areaCode = areaCode;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getIntroduction() {
        return introduction;
    }

    public void setIntroduction(String introduction) {
        this.introduction = introduction;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getRealName() {
        return realName;
    }

    public void setRealName(String realName) {
        this.realName = realName;
    }

    public double getLatitude() {
        return latitude;
    }

    public void setLatitude(double latitude) {
        this.latitude = latitude;
    }

    public double getLongitude() {
        return longitude;
    }

    public void setLongitude(double longitude) {
        this.longitude = longitude;
    }

    @Override
    public AppUser clone() throws CloneNotSupportedException {
        return new AppUser(this);
    }

    public void updateUser(User user) {
        this.showName = user.getShowName() == null ? this.showName : user.getShowName();
        this.loginName = user.getLoginName() == null ? this.loginName : user.getLoginName();
        this.mobile = user.getMobile() == null ? this.mobile : user.getMobile();
        this.address = user.getAddress() == null ? this.address : user.getAddress();
        this.areaCode = user.getAreaCode() == null ? this.areaCode : user.getAreaCode();
        this.introduction = user.getIntroduction() == null ? this.introduction : user.getIntroduction();
        this.headImage = user.getHeadImage() == null ? this.headImage : user.getHeadImage();
        this.email = user.getEmail() == null ? this.email : user.getEmail();
        this.latitude = user.getLatitude() == null ? this.latitude : Double.parseDouble(user.getLatitude());
        this.longitude = user.getLongitude() == null ? this.longitude : Double.parseDouble(user.getLongitude());
    }

    public void updateBindUser(BindUser user) {
        this.bindName = user.getLoginName() == null ? this.bindName : user.getLoginName();
        this.bindPwd = user.getPassword() == null ? this.bindPwd : user.getPassword();
    }

    public BindUser assistToBindUser() {

        BindUser bu = new BindUser();
        bu.setLoginName(this.bindName);
        bu.setPassword(this.bindPwd);
        bu.setUserId(this.id);
        return bu;
    }

    public void putBindUser(String loginIotName,String loginIotPassword){
        this.loginIotName = loginIotName == null ? this.loginIotName : loginIotName;
        this.loginIotPassword = loginIotPassword == null ? this.loginIotPassword : loginIotPassword;

    }
}
